<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Recovery extends Model
{   
    const STATUS_PASS = 1;

    const STATUS_WAIT = 0;

    public static $STAUTS = [
        self::STATUS_PASS => '已完成',
        self::STATUS_WAIT => '未完成'
    ];

    protected $table = 'recoveries';

    protected $fillable = [
    	'id',
    	'type_id',
    	'volumn',
    	'weight',
    	'photos',
    	'address',
    	'status',
        'customer_id'
    ];

    protected $appends = [
        'status_desc',
        'photos_array'
    ];

    public function getStatusDescAttribute(){
        if(array_key_exists('status',$this->attributes)){
            return $this->attributes['status_desc'] = self::$STAUTS[$this->attributes['status']];
        }
    }

    public function getPhotosArrayAttribute(){
        if(array_key_exists('photos',$this->attributes)){
            return $this->attributes['photos_array'] = json_decode($this->attributes['photos']);
        }
    }

    public function recoveryType(){
        return $this->belongsTo('App\Models\RecoveryType','type_id','id');
    }
}
